package com.googlecode.imanager.client;

import com.googlecode.imanager.client.bridge.ILabel;
import com.googlecode.imanager.client.util.HasText;
import com.googlecode.imanager.client.value.HasValueType;
import com.googlecode.imanager.client.value.ValueType;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class Label extends Control implements ILabel, HasText, HasValueType {

    private static final long serialVersionUID = 1L;

    private String text;
    private ValueType valueType;
    private Focusable target;
    private boolean overflowVert;    
    private boolean overflowHorz; // FIXME maybe not supported
    
    
    public Label() {
        super();
        text = "";
    }

    public Label(Container parent) {
        this();
        setParent(parent);
    }
    
    @Override
    protected void onClick() {
        if (target != null){
            target.focus();
        }
        super.onClick();
    }

    public String getText() {
        return text;
    }
    
    public void setText(String text) {
        if (text == null){
            text = "";
        }
        if (!this.text.equals(text)){
            this.text = text;
            getBridge().setText(text);
        }
    }
    
    public boolean isOverflowVert() {
        return overflowVert;
    }
    
    public void setOverflowVert(boolean overflowVert) {
        if (this.overflowVert != overflowVert){
            this.overflowVert = overflowVert;
            getBridge().setOverflowVert(overflowVert);
        }
    }
    
    public boolean isOverflowHorz() {
        return overflowHorz;
    }
    
    public void setOverflowHorz(boolean overflowHorz) {
        if (this.overflowHorz != overflowHorz){
            this.overflowHorz = overflowHorz;
            getBridge().setOverflowHorz(overflowHorz);
        }
    }

    public void setTarget(Focusable target) {
        this.target = target;
    }

    public Focusable getTarget() {
        return target;
    }    

    public ValueType getValueType() {
        return valueType;
    }

    public void setValueType(ValueType valueType) {
        this.valueType = valueType;
    }

    @Override
    protected ILabel getBridge() {
        return (ILabel) lookupBridge();
    }

    @Override
    public Label clone() {
        return (Label) super.clone();
    }

}
